<template>
  <base-breadcrumb v-loading="loading">
    <div class="about-master-container">
      <a-card>
        <title-name title="信息详情" />
        <BForm :config="formConfig" :form="form" />
      </a-card>
      <a-card>
        <title-name title="获奖记录" />
        <b-table
          :show-page="false"
          :scroll="{x:1376}"
          ref="table"
          :columns="columns"
          :request="loadData"
        >
          <template slot="images" slot-scope="text, record, index">
            <l-table
              v-if="record.images && record.images.length > 0"
              uploadType="image"
              :disabled="true"
              :editModel="0"
              :uploadArrys.sync="record.images"
              multiple
            />
            <span v-else>无</span>
          </template>
          <template slot="actions" slot-scope="text, record, index">
            <a @click="del(record)">删除</a>
          </template>
        </b-table>
      </a-card>
      <div class="tool-btns tool-btns--fixed page-btn-right-top">
        <a-button class="ml12" type="default" @click="$close"> 关闭</a-button>
      </div>
    </div>
  </base-breadcrumb>
</template>

<script>
import UploadList from '@/components/UploadList'
import Api from '@/api/safetySupervision/safetyStar/createCardLog'

export default {
  name: 'createCardLogAdd',
  components: {
    UploadList
  },
  computed: {
    formConfig() {
      return [
        {
          row: true,
          children: [
            { type: 'input', value: 'employeeName', label: '姓名', attrs: { disabled: true } },
            { type: 'input', value: 'viewName', label: '所属单位', attrs: { disabled: true }, colSpan: 16 },
            // { type: 'input', value: 'branchComName', label: '分公司名称', attrs: { disabled: true } },
            // { type: 'input', value: 'projectName', label: '项目名称', attrs: { disabled: true } },
            { type: 'input', value: 'subcontractorName', label: '当前所属分包', attrs: { disabled: true } },
            { type: 'input', value: 'teamName', label: '班组', attrs: { disabled: true } },
            { type: 'input', value: 'sex', label: '性别', attrs: { disabled: true } },
            { type: 'input', value: 'idCard', label: '身份证号', attrs: { disabled: true } },
            { type: 'input', value: 'honerSize', label: '获奖次数', attrs: { disabled: true } },
            { type: 'input', value: 'phone', label: '联系电话', attrs: { disabled: true } },
            { type: 'input', value: 'birthday', label: '出生日期', attrs: { disabled: true } }
          ]
        }
      ]
    }
  },
  data() {
    return {
      loading: false,
      form: { winningRecordDTOS: [], viewName: "" },
      columns: [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          customRender() {
            return Number(arguments[2]) + 1
          }
        },
        { title: '时间', dataIndex: 'createTime', width: 130 },
        { title: '发放人', dataIndex: 'issuer', width: 100 },
        { title: '施工区域', dataIndex: 'respAreaName', width: 130 },
        { title: '表彰卡数量', dataIndex: 'cardSize', width: 130 },
        {
          title: '表彰卡面额', dataIndex: 'behaviorStarCardDTOS', width: 130,
          customRender(text, record, index) {
            if (text) {
              return text.reduce((acc, cur, inx) => {
                acc = acc + cur.cardValue
                return acc
              }, 0)
            }
            return ''
          }
        },
        { title: '获奖理由', dataIndex: 'rewardReasons', width: 150 },
        {
          title: '照片', dataIndex: 'images',
          scopedSlots: { customRender: 'images' }
        },
        { title: '备注', dataIndex: 'remark', width: 100 },
        {
          title: '操作', dataIndex: 'actions', width: 100,
          scopedSlots: { customRender: 'actions' }
        }
      ],
      loadData: () => {
        return { code: 200, data: this.form.winningRecordDTOS || [] }
      }
    }
  },
  created() {
    this.getData()
  },
  methods: {
    async getData() {
      this.loading = true
      let res = await Api.findBusById({}, { id: this.$route.query.id })
      if (res.code === this.SUCCESS_CODE) {
        this.form = res.data
        this.form.sex = this.form.sex == 1 ? '男' : '女'
        this.form.viewName = this.form.branchComName + '/' + this.form.projectName
        this.$refs.table.refresh()
      }
      this.loading = false
    },
    del(row) {
      this.$delList3(Api.deleteByID, this.getData, { id: row.id })
    }
  }
}
</script>
